<template>
  <div class="campus-binhai">
    <h1>温州理工滨海校区学生查询</h1>
    <input v-model="studentId" placeholder="请输入学号" @keyup.enter="searchStudent">
    <button @click="searchStudent">查询</button>
    <div v-if="studentInfo">
      <h3>学生信息</h3>
      <p>学号: {{ studentInfo.id }}</p>
      <p>姓名: {{ studentInfo.name }}</p>
      <p>年龄: {{ studentInfo.age }}</p>
      <p>专业: {{ studentInfo.major }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CampusBinhai',
  data() {
    return {
      studentId: '',
      studentInfo: null,
      students: [
        { id: '1001', name: '张三', major: '计算机科学与技术',age: 20 },
        { id: '1002', name: '李四', major: '软件工程',age: 21 },
        { id: '1003', name: '王五', major: '网络工程' ,age: 22}
      ]
    }
  },
  methods: {
    searchStudent() {
      this.studentInfo = this.students.find(student => student.id === this.studentId);
      if (!this.studentInfo) {
        alert('未找到该学号的学生');
      }
    }
  }
}
</script>